<?php
// <copyright file="AuthenticationType.cs" company="NQtec">
// Copyright (c) 2008, 2009 All Right Reserved, http://www.dqer.com/
// Copyright (c) 2008, 2009 All Right Reserved, http://www.nqtec.com/
//
// This source is part of the DQER library that released under the LGPL.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Victor Gatkov</author>
// <email>v.gatkov@nqtec.com</email>
// <email>info@dqer.com</email>
// <date>2008-09-11</date>
// <summary>Contains a base, abstract class for an AuthorisationPolicyProvider</summary>

class MySQLDB {
   var $connection;
   var $srv;
   var $usr;
   var $pas;
   var $dbn;

   function MySQLDB($srv, $usr, $pas, $dbn){
      $this->connection = mysql_connect($srv, $usr, $pas) or die(mysql_error());
      mysql_select_db($dbn, $this->connection) or die(mysql_error());
      // register_shutdown_function(array(&$this, 'close'));
   }
   function query($query){
//      $query = mysql_real_escape_string($query);
      return mysql_query($query, $this->connection);
   }
   function sanitize($input){
//      if(!get_magic_quotes_gpc()) {
//	      $input = addslashes($input);
//      }
      $input = mysql_real_escape_string($username);
      return $input;
   }
   function fetchAarray($result) {
      return mysql_fetch_array($result);
   }
   function do_query($q) {
       global $database;
       $result = mysql_query($q, $this->connection);
       return $result;
   }

   function table_exists($table) {
       global $database;
        $result = mysql_query("show tables like '$table'",$this->connection) or die ('error reading database');
        if (mysql_num_rows ($result)>0) return true;
        else return false;
   }
   function close() {
      mysql_close($this->connection);
   }
};

?>
